<template>
<div class="photoinfo-comtainer">
    <h2>{{photoinfo.title}}</h2>
    <p class="subtitle">
        <span>发表时间：{{photoinfo.add_time | dataFormat}}</span>
        <span>点击次数：{{photoinfo.click}}</span>
    </p>
    <hr>
   <!-- 图片缩略图区域 -->
    <div class="thumbs">
    <vue-preview
      :list="list"
      :thumbImageStyle="{width: '80px', height: '80px', margin: '10px'}"
      :previewBoxStyle="{border: '1px solid #eee'}"
      :tapToClose="true"
      @close="closeHandler"
      @destroy="destroyHandler"
    />
    </div>
    <div class="content" v-html="photoinfo.content"></div>
    <comment :id="this.id"></comment>
</div>
</template>

<script>
import { Toast } from 'mint-ui';
import comment from '../subcomponents/comment.vue'
export default {
    data(){
        return{
            id: this.$route.params.id,
            photoinfo:{},
            list:[]
        }
    },   
    created(){
        this.getPhotoInfo();
        this.getThumbs();
    },
    methods:{
        getPhotoInfo(){
            this.$http.get('api/getimageInfo/'+this.id).then(result =>{
                if(result.body.status === 0){
                    this.photoinfo = result.body.message[0]
                }else{
                    Toast('获取图片信息失败！')
                }
            })
        },
        getThumbs(){
            this.$http.get('api/getthumimages/'+this.id).then(result =>{
                if(result.body.status === 0){
                    result.body.message.forEach(item =>{
                        item.w = 600;
                        item.h = 400;
                    })
                    this.list = result.body.message;
                }
            })
        },
        closeHandler() {
            console.log('closeHandler')
        },
        // 完全关闭之后，调用这个函数清理资源
        destroyHandler() {
            console.log('destroyHandler')
        }
    },
    components:{
    comment
    }
}
</script>

<style lang="scss">
.photoinfo-comtainer{
    padding: 2px;
    h2{
        color: chocolate;
        font-size: 16px;
        text-align: center;
        margin: 15px 0;
    }
    .subtitle{
        display: flex;
        justify-content: space-between;
        font-size: 14px;
        margin-bottom: 4px;
    }
    .content{
        line-height: 25px;
        font-size: 16px;
    } 
}     
.thumbImg{
    margin-bottom: 5px !important;
    box-shadow: 0 0 12px #999 !important; 
}
</style>
